package darknet.application.filesharing.impl;

import darknet.application.filesharing.spec.Hash;
import java.io.File;

/**
 * SHA-1 implementation of a hash.
 * 
 * @author yoyo
 */
public class SHA1Hash implements Hash {

    /** String representation of the hash. */
    private String stringValue = null;

    /**
     * Initialize a SHA-1 hash with the string value of the hash.
     * 
     * @param stringValue
     */
    SHA1Hash(String stringValue) {

        if (stringValue == null || stringValue.length() == 0) {
            throw new IllegalArgumentException("stringValue is invalid");
        }
        this.stringValue = stringValue;
    }

    /**
     * Initialize a SHA-1 hash with the file to hash (may take long time).
     *
     * @param fileToHash The file to hash. Must be a file, not a directory.
     */
    SHA1Hash(File fileToHash) {

        if (fileToHash == null || fileToHash.isDirectory()) {
            throw new IllegalArgumentException("fileToHash is invalid");
        }

        // TODO Compute hash of the entire file.
    }

    /**
     * Initialize a SHA-1 hash, for chunk purpose, for a part of the given file.
     *
     * @param fileToHashPartially The file to hash partially.
     * @param chunkOrderNumber    The chunk order. Be careful to OutOfBounds.
     */
    SHA1Hash(File fileToHashPartially, Integer chunkOrderNumber) {

    }

    @Override
    public String getStringValue() {
        return stringValue;
    }

}
